package com.syg.main;

import com.syg.entity.BasisInfo;
import com.syg.util.EntityInfoUtil;
import com.syg.util.Generator;
import com.syg.util.MySqlToJavaUtil;

import java.sql.SQLException;

/**
 * Copyright: Copyright (c) 2019
 *
 * <p>说明： 自动生成工具</P>
 * <p>源码地址：</P>
 * @author ps
 */
public class GeneratorMain {
    /************* 基础信息：项目名、作者、版本 ************/
    public static final String PROJECT = "wallet-sign";
    public static final String AUTHOR = "ps";
    public static final String VERSION = "V1.0";
    /************* 数据库连接信息：连接URL、用户名、秘密、数据库名 ************/
    public static final String URL = "jdbc:mysql://10.94.80.40:3306/config_dev?useUnicode=true&useSSL=false&characterEncoding=utf8";
    public static final String NAME = "zycfc";
    public static final String PASS = "Zycfc@666";
    /************* 可以通过连接名获取数据库名字,这里不需要指定 ************/
    public static final String DATABASE = "config_dev";
    /************* 类信息：类名、对象名（一般是【类名】的首字母小些）、类说明、时间 ************/
    public static final String CLASSNAME = "foreign";
    public static final String TABLE = "t_class";
    public static final String CLASSCOMMENT = "API应用KEY";
    public static final String TIME = "2019年10月16日";
    public static final String AGILE = System.currentTimeMillis() + "";
    /************* 路径信息，分开路径方便聚合工程项目，微服务项目 ************/
    public static final String ENTITY_URL = "com.syg.power.entity";
    public static final String DAO_URL = "com.syg.power.mapper";
    public static final String XML_URL = "com.syg.power.mapper.xml";
    public static final String SERVICE_URL = "com.syg.power.service";
    public static final String SERVICE_IMPL_URL = "com.syg.power.service.impl";
    public static final String CONTROLLER_URL = "com.syg.power.web";
    /************* 是否是Swagger配置 ************/
    public static final String IS_SWAGGER = "false";

    public static void main(String[] args) {
        BasisInfo bi = new BasisInfo(PROJECT, AUTHOR, VERSION, URL, NAME, PASS, DATABASE, TIME, AGILE, ENTITY_URL,
                DAO_URL, XML_URL, SERVICE_URL, SERVICE_IMPL_URL, CONTROLLER_URL,IS_SWAGGER);
        bi.setTable(TABLE);
        bi.setEntityName(MySqlToJavaUtil.getClassName(TABLE));
        bi.setObjectName(MySqlToJavaUtil.changeToJavaFiled(TABLE));
        bi.setEntityComment(CLASSCOMMENT);
        try {
            EntityInfoUtil.getInfo(bi);
            // 生成文件存放位置
            String fileUrl = "D:\\home\\";
            //开始生成文件
            String aa1 = Generator.createEntity(fileUrl, bi).toString();
            String aa2 = Generator.createDao(fileUrl, bi).toString();
            String aa3 = Generator.createDaoImpl(fileUrl, bi).toString();
            String aa4 = Generator.createService(fileUrl, bi).toString();
            String aa5 = Generator.createServiceImpl(fileUrl, bi).toString();
            String aa6 = Generator.createController(fileUrl, bi).toString();
            // 是否创建swagger配置文件
            String aa7 = Generator.createSwaggerConfig(fileUrl, bi).toString();

            System.out.println(aa1);
            System.out.println(aa2);
            System.out.println(aa3);
            System.out.println(aa4);
            System.out.println(aa5);
            System.out.println(aa6);
            System.out.println(aa7);

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
